package com.yz.jdd.base.utils;

import android.content.Context;
import android.text.TextUtils;

/**
 * Created by shibin on 2017/2/8.
 */

public class PayConfig {
    //重试轮询时间间隔
    public static final int PROID_TIME_RETYR = 2000;

    //支付方式
    public static final String TYPE_PAY_COUNT = "0";//交易汇总
    public static final String TYPE_PAY_CASH = "1";//现金支付
    public static final String TYPE_PAY_ALIPAY = "2";//支付宝支付
    public static final String TYPE_PAY_MEMBERCARD = "3";//会员卡支付
    public static final String TYPE_PAY_UNION = "4";//银联支付
    public static final String TYPE_PAY_WEIXIN = "5";//微信支付
    public static final String TYPE_PAY_YUNSHANFU = "7";//云闪付支付
    public static final String TYPE_PAY_SCAN = "6";// 主扫微信、支付宝
    public static final String TYPE_PAY_MINISTOREVALUE = "8";// 余额

    public static final String TYPE_PAY_SCAN_STR = "scan_pay";//扫码支付 包含支付宝 微信
    public static final String TYPE_PAY_ALI_STR = "ali_pay";
    public static final String TYPE_PAY_WEIXIN_STR = "weixin_pay";
    public static final String TYPE_PAY_CASH_STR = "cash_pay";
    public static final String TYPE_PAY_MEMBERCARD_STR = "membercard_pay";
    public static final String TYPE_PAY_UNION_STR = "union_pay";
    public static final String TYPE_PAY_HUABEI_STR = "huabei_pay";


    //结果页订单类型
    public static final String TYPE_ORDER_DEAL = "1";//交易订单
    public static final String TYPE_ORDER_RECHARGE = "2";//储值订单
    public static final String TYPE_ORDER_REFUND = "3";//退款订单
    public static final String TYPE_ORDER_CANCEL = "4";//异常--撤销订单
    public static final String TYPE_ORDER_DISH = "5";//点餐订单
    //支付结果订单状态
    public static final String ORDER_STATUS_UNPAY = "0";//未付款
    public static final String ORDER_STATUS_PAYING = "1";//付款中
    public static final String ORDER_STATUS_SUCCESS = "2";//付款成功
    public static final String ORDER_STATUS_FAILUER = "3";//付款失败
    public static final String ORDER_STATUS_CODE_2421 = "2421";//收款异常-->2421 收款异常请关单
    public static final String ORDER_STATUS_CODE_2402 = "2402";//收款异常-->2402 结果页显示
    public static final String ORDER_CANCEL_CODE_2008 = "2008";//撤销失败-->2008 撤销失败位置错误
    public static final String ORDER_CANCEL_CODE_2009 = "2009";//撤销失败-->2009 超过5分钟限制
    public static final String ORDER_STATUS_HUABEI_FAILUER = "2019";//花呗分期扫码错误

    public static final String DISHORDER_FAILURE_CODE_6005 = "6005";//订单已经支付了
    public static final String DISHORDER_FAILURE_CODE_6007 = "6007";//订单已经取消
    public static final String DISHORDER_FAILURE_CODE_6008 = "6008";//订单正在支付中，不能重新支付
    public static final String DISHORDER_FAILURE_CODE_6009 = "6009";//订单支付异常，不能支付


    public static final String INTENT_ORDER_FROM = "intent_order_from";//Request_Pay参数传递key

    public static final String INTENT_ORDER_REPAY = "intent_order_repay";//Request_Pay参数传递key

    public static final String INTENT_PAY_DATA = "intent_pay_data";//支付数据采集 , 结果页面参数传递key

    ///subPayType
    public static final String TYPE_SUBPAY_TOSCAN = "1";//扫码
    public static final String TYPE_SUBPAY_PAYMENT = "2";//收款码
    /**
     * 餐前餐后付款 model
     */
    public static final String MODEL_DISH_BEFORE = "1";//餐前模式
    public static final String MODEL_DISH_AFTER = "2";//餐后模式

    //支付前 -- intent bundle keys

    public static final String INTENT_TYPE_VERIFY = "1";//验证会员

    public static final String INTENT_TRACENO = "intent_traceno";//原始流水号


    //    public static final String INTENT_ORDERTYPE = "intent_ordertype";//订单类型:1:交易订单 2:储值订单;
    public static final String INTENT_ORDERID = "intent_orderid";//订单ID：重新支付需要传
    public static final String INTENT_PAYTYPE = "intent_paytype";//支付方式 1:现金 2:支付宝 3:会员卡 4:银联,5:微信 6-发票（自定义）
    public static final String INTENT_TOTALAMOUNT = "intent_totalamount";//订单总金额
    public static final String INTENT_RECEIPTAMOUNT = "intent_receiptamount";//实收金额
    //    public static final String INTENT_VOUCHERAMOUNT = "intent_voucheramount";//优惠金额&充值赠送金额
//    public static final String INTENT_GOOODSAMOUNT = "intent_gooodsAmount";//商品核销金额
    public static final String INTENT_GOODSNAME = "intent_goodsname";//商品名
    public static final String INTENT_COUPONCODE = "intent_couponcode";//核销券码
    public static final String INTENT_USEDATE = "intent_usedate";//券使用时间
    public static final String INTENT_OPERATOR = "intent_operatorname";//收银员

    public static final String INTENT_AUTHCODE = "intent_authcode";//支付宝条码支付：支付授权码
    public static final String INTENT_MEMBERCARDID = "intent_membercardid";//会员卡号
    public static final String INTENT_MEMBERBALANCE = "intent_membercardbalance";//会员余额
    public static final String INTENT_MEMBERCARD_HASPWD = "intent_haspwd";//是否有支付密码

    public static final String INTENT_MEMBERMOBILE = "intent_membercardmobile";//手机号

    public static final String INTENT_CANCEL_ORDER_RESULT_TITLE = "intent_cancel_result_title";//撤销成功，撤销失败，撤销中

    public static final String INTENT_RESULT_MESSAGE = "intent_result_msg";//结果页信息
    public static final String INTENT_RESULT_CODE = "intent_result_code";//结果返回code
    public static final String INIENT_FIXED_SCAN = "inient_fixed_scan";//跳转固定金额收款
    //储值 -- intent bundle keys
//    public static final String INTENT_TEMPLATEID = "intent_templateid";//储值订单充值规则id
//    public static final String INTENT_RECHARGEAMOUNT = "intent_rechargeamount";//储值订单充值金额
//    public static final String INTENT_DONATEAMOUNT = "intent_donateamount";//赠送金额

    //退款 -- intent bundle keys
    public static final String INTENT_TRADENO = "intent_tradeNo";    //交易流水号
    public static final String INTENT_ORDERAMOUNT = "intent_orderamount";//订单总金额
    //    public static final String INTENT_REFUNDMONEY = "intent_refundmoney";//退款金额
//    public static final String INTENT_REFUNDREASON = "intent_refundreason";//退款原因
//    public static final String INTENT_REFUND_PWD = "intent_refund_pwd";//退款密码
//    public static final String INTENT_REFUND_FAILREASON = "intent_refund_failreason";//退款失败原因
//    public static final String INTENT_REFUNDID = "intent_refundid";//退款id
//    public static final String INTENT_REFUNDSTATUS = "intent_refundstatus";//退款状态
//    public static final String INTENT_REFUND_THIRDNO = "intent_refund_thirdno";//第三方退款码
    public static final String INTENT_REFUND_INVOICESTATUS = "intent_invoiceStatus";//第三方退款码


    //撤销异常状态
    public static final String ORDER_PAY_ERROR_NET = "网络连接失败，请检查网络连接后，\n" +
            "刷新订单列表查看支付结果。";
    public static final String ORDER_PAY_ERROR_OTHER = "网络异常，请检查网络连接后，\n" +
            "刷新订单列表查看支付结果。";
    public static final String ORDER_PAY_ERROR_TIMEOUT = "服务响应超时，请检查网络连接后，\n" +
            "刷新订单列表查看支付结果。";

    /**
     * 获取clientOrderId ，生成新的clientOrderId并保存
     * 客户端订单号规则：【6位yyMMDD（年月日） + 2位路由（分库分表） + 4位终端识别码（同一商户唯一） + 6位自增 】
     *
     * @param context
     */
    public static synchronized String createClientOrderId(Context context) {
        String clientOrderId = PreferencesUtils.getString(context, BaseConfigs.PREFS_CURRENT_CLIENTID, "");
        //先取最新key对应的value
        String pos_suppliercode = PreferencesUtils.getString(context, BaseConfigs.POS_SUPPLIERCODE, "");
        if (TextUtils.isEmpty(pos_suppliercode)) {
            //再取旧的value
            pos_suppliercode = PreferencesUtils.getString(context, BaseConfigs.POS_SN, "");
        }

        if (!TextUtils.isEmpty(clientOrderId) && !Tools.getDate().equals(clientOrderId.substring(0, 5)) && 18 == clientOrderId.length() && pos_suppliercode.equals(clientOrderId.substring(8, 11))) {
            PreferencesUtils.putString(context, BaseConfigs.PREFS_CURRENT_CLIENTID, String.valueOf(Long.valueOf(clientOrderId) + 1));
            return clientOrderId;
        } else {
            clientOrderId = Tools.getDate() + PreferencesUtils.getString(context, BaseConfigs.STRING_ROUTERCODE, "") + pos_suppliercode + Tools.getTime();
            PreferencesUtils.putString(context, BaseConfigs.PREFS_CURRENT_CLIENTID, String.valueOf(Long.valueOf(clientOrderId) + 1));
            return clientOrderId;
        }


    }

}
